﻿@{
    ViewBag.Title = "ProductDetail";    
}
<div id="cphMain_ctl00_ContentPane" class="center">
    <div id="Breadcrumb" class="Breadcrumb">
        <ul>
            <li class="first">
                <a href='javascript:;' onclick="javascript:loadAction('Index2','Main')">Trang chủ
                </a>
            </li>
            <li>
                <a href='javascript:;' onclick="javascript:loadAction('ProductList','Admin')">Danh sách sản phẩm</a>
            </li>
            <li>
                <span>Thông tin sản phẩm</span>
            </li>
        </ul>
    </div>

<div class="Account-Module DefaultModule">
    
<script type="text/javascript">
function keypress(e) {
    var keypressed = null;
    if (window.event) { keypressed = window.event.keyCode; }
    else { keypressed = e.which; }
    if (keypressed < 48 || keypressed > 57) {
        if (keypressed == 8 || keypressed == 127 || keypressed == 0) { return; }
        return false;
    }
}
</script>
<div class="DefaultModule LoginForm Block Block2">
    <span style="display: none;">
        </span>
    <div id="CreateAccountForm" class="Block Moveable Panel CreateAccountForm">
        
        <div id="cphMain_ctl00_ctl01_ctl00_pnlInfo">
	
            <div class="BlockContent">
                <div class="defaultTitle LoginForm-title">
                    <h1>
                        Thông tin sản phẩm
                    </h1>
                </div>
                <form action="/Admin/ProductDetailClick" method="post" onsubmit="return productDetailValidation(this);" enctype="multipart/form-data" >
                <div class="defaultContent LoginForm-content CreateAccountContainer">                    
                    <h3>Thông tin bắt buộc</h3>
                    <div class="FormContainer HorizontalFormContainer NarrowFormContainer">
                        <dl>
                            @if(Model.ID > 0)
                            {
                            <dt>
                                <span class="required">*</span> ID:
                            </dt>
                            <dd>
                                <input name="proID" type="text" value="@Model.ID"
                                    id="proID" class="NormalTextBox" readonly="true" 
                                    style="width:100px;">                                                                    
                            </dd>
                            }
                            <dt>
                                <span class="required">*</span> Tên sản phẩm:
                            </dt>
                            <dd>
                                <input name="proName" type="text" value="@Model.name"
                                    id="proName" class="NormalTextBox" 
                                    style="width:200px;">                                                                    
                            </dd>
                            
                            <dt>
                                <span class="required">*</span> Nhà sản xuất:
                            </dt>
                            <dd>
                                <select name="category" id="category" class="NormalTextBox" style="width:200px;" > 
                                    
                                    @foreach (var cate in ViewBag.category)
                                    {
                                        if (Model.category_ID == cate.Key)
                                        {
                                            <option value="@cate.Key" selected="selected">@cate.Value</option>                                        
                                        }
                                        else
                                        {
                                            <option value="@cate.Key">@cate.Value</option>                                        
                                        }
                                        
                                    }
                                </select>                                                                                               
                            </dd>
                            <dt><span class="required">*</span> Nhóm sản phẩm:</dt>
                            <dd>                                
                                <input list="groupList" name="group_name" id="group_name" autocomplete="off"
                                    class="NormalTextBox" style="width:200px;" value="@Model.group_name"/>                                                                   
                            </dd>    
                            <dt>
                                <span class="required">*</span> Loại:
                            </dt>
                            <dd>
                                @{var proTypeList = new string[] { "chai PET", "chai thủy tinh", "lon" };                                  
                                  }
                                <select name="type" id="type" class="NormalTextBox" style="width:200px;">                                     
                                        @foreach (var proType in proTypeList)
                                        {
                                            if (proType.Equals(Model.type))
                                            {
                                                <option value="@proType" selected="selected">@proType</option>
                                            }else
                                            {
                                                <option value="@proType">@proType</option>
                                            }
                                        }
                                </select>  
                            </dd>   
                            <dt><span class="required">*</span> Thể tích (ml):</dt>
                            <dd>
                                <input name="volume" type="text" id="volume" class="NormalTextBox" value="@Model.volume"
                                    style="width:200px;" onkeypress="javascript: return keypress(event);">                                                                                                                              
                            </dd>       
                            <dt><span class="required">*</span> Số lượng trong kho:</dt>
                            <dd>
                                <input name="capacity" type="text" id="capacity" class="NormalTextBox" value="@Model.capacity"
                                    style="width:200px;" onkeypress="javascript: return keypress(event);">                                                                                                                              
                            </dd>                  
                            <dt><span class="required">*</span> Số lượng / thùng:</dt>
                            <dd>
                                <input name="amount" type="text" id="amount" class="NormalTextBox" value="@Model.amount"
                                    style="width:200px;" onkeypress="javascript: return keypress(event);">                                                                                                                              
                            </dd>                         
                            <dt><span class="required">*</span> Giá tiền / thùng:</dt>
                            <dd>
                                <input name="price" type="text" id="price" class="NormalTextBox"  value="@Convert.ToInt32(Model.price)"
                                    style="width:200px;" onkeypress="javascript: return keypress(event);">                                                                                                                              
                            </dd>            
                            @if(Model.image_link != null)
                            {
                            <dt></dt>             
                            <dd> 
                                <img src="/Content/data/images/350.300/@Model.image_link" height="300" id="blah"/>
                            </dd>
                            }else
                            {
                                <dt></dt>             
                                <dd> 
                                <img id="blah" src="#" alt="your image" style="display:none;" height="300"/>
                            </dd>
                            }
                            <dt><span class="required">*</span> Hình ảnh:</dt>
                            <dd>                                
                                <input name="image_link" type="file" id="image_link" class="NormalTextBox" 
                                    style="width:250px;" accept="image/*">                                                                
                            </dd>                         
                                 
                            <dt>
                                <span class="required">*</span> Mô tả sản phẩm:
                            </dt>
                            <dd>
                                <textarea name="description" 
                                    id="description" class="NormalTextBox" 
                                    style="width:300px; height:200px">@Model.description</textarea>                                                                    
                            </dd>        
                            <dt><span class="required">*</span> Đang bán:</dt>
                            <dd>
                                @{string sellingCheck = "checked='checked'";
                                  if(Model.is_selling != null && Model.is_selling == false)
                                  { sellingCheck = ""; }
                                  }
                                <input name="is_selling" type="checkbox" id="is_selling" 
                                    class="NormalTextBox" value="is_selling" @sellingCheck> 
                            </dd>          
                            
                        </dl>
                    </div>
                    <p>
                    </p>
                    <h3>
                        Thông tin không bắt buộc
                    </h3>
                    
                    <div class="FormContainer HorizontalFormContainer NarrowFormContainer">
                        <dl>                            
                            <dt>
                                Có khuyến mãi:
                            </dt>
                            <dd>
                                @{ string promotionCheck = "";
                                   if (Model.promotion_ID != null) { promotionCheck = "checked='checked'"; }
                                }                                
                                <input name="is_promotion" type="checkbox" id="is_promotion" class="NormalTextBox" @promotionCheck>                                                                                                                                                              
                            </dd>
                            <dt>
                                Tên khuyến mãi:
                            </dt>
                            <dd>
                                <select name="promotion" id="promotion" class="NormalTextBox" style="width:200px;">                                     
                                     @foreach (var p in ViewBag.promotion)
                                     {
                                         if (p.ID == Model.promotion_ID)
                                         {
                                         <option value="@p.ID" selected="selected">@p.title</option>    
                                         }else
                                         {
                                             <option value="@p.ID">@p.title</option>
                                         }
                                         
                                     }
                                </select>                                                                                                
                            </dd>
                            
                            
                            <dt>&nbsp;</dt>
                            <dd>
                                <input type="submit" name="btnSubmit" value="Cập nhật sản phẩm"                                     
                                    class="CreateAccountButton">                                                                
                            </dd>
                        </dl>
                    </div>
                    <p>
                    </p>
                </div>
                    </form>
                <div class="defaultFooter LoginForm-footer"><div></div></div>
            </div>
        
</div>
    </div>
</div>    


<script type="text/javascript">
    
    //preview hinh anh sau khi chon file
    (function ($) {
        function readURL(input) {
            var $prev = $('#blah');

            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $prev.attr('src', e.target.result);
                    
                }

                reader.readAsDataURL(input.files[0]);

                $prev.show();
            } else {
                $prev.hide();
            }
        }

        $('#image_link').on('change', function () {
            readURL(this);
        });
    })(jQuery);

    
    $(document).ready(function () {
        
        window.onload = function () {
            changeGroupName();
            changePromotion();
        }
        $("#category").change(function () {
            changeGroupName();            
        });
        $("#is_promotion").change(function () {
            changePromotion();
        });                        
    });
</script>
</div>
</div>

